package LFhalf {
	import LFhalf.PlayerInput;
	import tea.lib.Point3d;
	import tea.lib.BmpList;
	
	class char extends phyObject {
		public var currentItem:Item;
		public var controler:uint=0;
		public var team:uint=0;
		public var walkFrame:uint = 0;
		public var mCA:charAction;
		public var data:XML;
		public function char(_tag:String,_obj:Object = null):void {
			super(_tag,_obj);
			objectType = 'char';
			var pbjdata:XMLList = DataProcesser.instance.getObj(_tag);
			data=DataProcesser.instance.getData(_tag)
			mCA = new charAction(this);
			currentAction = 'normal';
			currentFrame = 0;
			currentWait = 0;
			
			var tempbmpList:Array = [];
			for (var pathKey:String in data.detail.photo.path) {
				tempbmpList.push(data.detail.photo.path[pathKey]);
			}
			//obj ref
			BmpList.shareBmpList.addPhotos(tempbmpList);
		}
		private function frameAction(_stateID:uint, _input:PlayerInput):void {
			curerntInput = _input;
			currentState = _stateID;
			if (_stateID == 1) {//normal,walk,tired
				inputChangeDirect()
				if(mCA.doSkill()){
				}else if(mCA.doDash()){
				}else if(mCA.doRun()){
				}else if(mCA.doJump()){
				}else if(mCA.doCatch()){
				}else if(mCA.doItem()){
				}else if(mCA.doAttack()){
				}else if(mCA.doDefend()){
				}else if(mCA.doWalk()){
				}
			}else if (_stateID == 2) {//run
				if (clickBack) {
					jumpState("stop_run");
					return;
				}
				if(mCA.doSkill()){
				}else if(mCA.doDefend()){
				}else if(mCA.doItem()){
				}else if(mCA.doAttack()){
				}
			}else if (_stateID == 3) {//ready jump
				inputChangeDirect()
			}else if (_stateID == 4) {//sky
				inputChangeDirect()
				if(mCA.doSkill()){
				}else if(mCA.doItem()){
				}else if(mCA.doAttack()){
				}
			}else if (_stateID == 5) {//jump down
				if(mCA.doDash()){
				}else if(mCA.doDefend()){
				}
			}else if (_stateID == 6) {//dash
				if (clickBack) {
					frameAction(6, _input);
					return;
				}
			}else if (_stateID == 7) {//dash back
				if (clickFront) {
					frameAction(6, _input);
					return;
				}
				if(mCA.doSkill()){
				}else if(mCA.doItem()){
				}else if(mCA.doAttack()){
				}
			}else if (_stateID == 8) {//defend
				inputChangeDirect();
				if (mCA.doSkill()) {
				}else if(mCA.doJump()){
				}else if(mCA.doItem()){
				}else if(mCA.doAttack()){
				}
			}else if (_stateID == 9) {//defend hit
				
			}else if (_stateID == 10) {//attack
				
			}else if (_stateID == 11) {
				
			}else {
				
			}
		}
		//
		function inputChangeDirect():void {
			if (clickBack) {
				faceRight = !faceRight;
			}
		}
		
		private function get clickBack():Boolean
		{
			return curerntInput.directX == (faceRight? -1:1);
		}
		
		private function get clickFront():Boolean
		{
			return curerntInput.directX == (faceRight? 1:-1);
		}
	}
}